package com.ke.forum.forumapi.controller;


import com.ke.forum.common.common.Result;
import com.ke.forum.forumapi.service.ArticleService;
import com.ke.forum.mbg.entity.Article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 珂
 * @since 2022-05-22
 */
@RestController
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    ArticleService articleService;

    @PostMapping("addArticle")
    public Result addArticle(@RequestBody Article article){
        return articleService.addArticle(article);
    }

    @PostMapping("updateArticle")
    public Result updateArticle(@RequestBody Article article){
        return null;
    }

    @GetMapping("deleteArticle")
    public Result deleteArticle(@RequestParam(value = "id") Integer id){
        return articleService.deleteArticle(id);
    }

    @GetMapping("listArticle")
    public Result listArticle(@RequestParam(value = "sectionId")Integer sectionId,
                              @RequestParam(value = "isRare",defaultValue = "false")Boolean isRare,
                              @RequestParam(value = "sortWay",defaultValue = "1")Integer sortWay,
                              @RequestParam(value = "page",defaultValue = "1")Integer current){
        return articleService.listArticle(sectionId, isRare, sortWay, current);
    }

    @GetMapping("getArticleInfo")
    public Result getArticleInfo(@RequestParam(value = "id")Integer id){
        return articleService.getArticleInfo(id);
    }

    @GetMapping("listArticleByUuid")
    public Result listArticleByUserId(@RequestParam(value = "uuid",required = false)String uuid,
                                      @RequestParam(value = "current",defaultValue = "1")Integer current){
        return articleService.listArticleByUserId(uuid,current);
    }

    @GetMapping("listTopArticle")
    public Result listTopArticle(@RequestParam(value = "sectionId") Integer sectionId){
        return articleService.listTopArticle(sectionId);
    }

    @GetMapping("listStarUserArticles")
    public Result listStarUserArticles(@RequestParam(value = "current",defaultValue = "1") Integer current){
        return articleService.listStarUserArticles(current);
    }
}

